package com.example.memurbac_service.dao;


import com.example.memurbac_service.pojo.Memutype;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MemutypeMapper
{
    /**
     * 添加菜单类型
     */
    @Insert("insert into t_memutype values(#{id},#{mt_name},#{mt_desc},0,now(),now(),#{mt_exaimg})")
    int addMemutype(Memutype memutype);


    /**
     * 修改菜单类型
     */
    @Update({"<script>",
            "update t_memutype set mt_name=#{mt_name},mt_desc=#{mt_desc},mt_modiftime=now()",
            "<if test='mt_exaimg!=null'>",
            ",mt_exaimg=#{mt_exaimg}",
            "</if>",
            "where id=#{id}",
            "</script>"})

    int upteMemutype(Memutype memutype);

    /**
     * 删除菜单类型
     */

    @Delete("delete from  t_memutype  where id=#{memutypeid}")
    int delMemutype(int memutypeid);

    /**
     * 根据菜单类型名字 模糊查询
     */
    @Select("select * from t_memutype where  mt_name like '%${memutypename}%' ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "mt_name",column = "mt_name"),
            @Result(property = "mt_desc",column = "mt_desc"),
            @Result(property = "mt_status",column = "mt_status"),
            @Result(property = "mt_createtime",column = "mt_createtime"),
            @Result(property = "mt_modiftime",column = "mt_modiftime"),
            @Result(property = "mt_exaimg",column = "mt_exaimg")
    })
    List<Memutype> reachMemutype(String memutypename);


    /**
     * 查询可用的菜单类型列表
     */
    @Select("select * from t_memutype where mt_status=0")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "mt_name",column = "mt_name"),
            @Result(property = "mt_desc",column = "mt_desc"),
            @Result(property = "mt_status",column = "mt_status"),
            @Result(property = "mt_createtime",column = "mt_createtime"),
            @Result(property = "mt_modiftime",column = "mt_modiftime"),
            @Result(property = "mt_exaimg",column = "mt_exaimg")
    })
    List<Memutype> reachallMemutype();



    /**
     * 停用菜单类型
     */
    @Update("update t_memutype set mt_status=1 where id=#{memutypeid}")
    int offMemutype(int memutypeid);

    /**
     * 启用菜单类型
     */
    @Update("update t_memutype set mt_status=0 where id=#{memutypeid}")
    int onMemutype(int memutypeid);

    /**
     * 根据id查询菜单类型
     */
    @Select("select * from t_memutype where  id=#{memutypeid} ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "mt_name",column = "mt_name"),
            @Result(property = "mt_desc",column = "mt_desc"),
            @Result(property = "mt_status",column = "mt_status"),
            @Result(property = "mt_createtime",column = "mt_createtime"),
            @Result(property = "mt_modiftime",column = "mt_modiftime"),
            @Result(property = "mt_exaimg",column = "mt_exaimg")
    })
    Memutype selectidMemutype(int memutypeid);

}
